package othersmodel

import (
	"fmt"
	"iptv_server/v3/src/database"
	"iptv_server/v3/src/settings"
	"strings"

	"gorm.io/gorm"
)

func InitDB(db *gorm.DB) {
	db.AutoMigrate(new(OthersDetail))
	db.AutoMigrate(new(OthersPlayList))
	Add()
}

func Add() {
	detail := &OthersDetail{
		ID:          1,
		Name:        "TODO1",
		Pic:         "/TODO_pic1",
		Year:        "2000",
		Remark:      "??",
		Area:        "area",
		Type:        "a/b/c",
		Actors:      "Z/Y/V",
		Director:    "Director",
		Description: "Description",
		FolderId:    1,
		DetailId:    1,
	}
	database.DB.Save(detail)

	detail = &OthersDetail{
		ID:          2,
		Name:        "TODO1",
		Pic:         "/TODO_pic1",
		Year:        "2000",
		Remark:      "??",
		Area:        "area",
		Type:        "a/b/c",
		Actors:      "Z/Y/V",
		Director:    "Director",
		Description: "Description",
		FolderId:    1,
		DetailId:    2,
	}
	database.DB.Save(detail)

	detail2 := &OthersDetail{
		ID:          3,
		Name:        "TODO2",
		Pic:         "videos/TODO_pic/xxxx.jpg",
		Year:        "2002",
		Remark:      "??",
		Area:        "area",
		Type:        "a/b/c",
		Actors:      "Z/Y/V",
		Director:    "Director",
		Description: "Description",
		FolderId:    2,
		DetailId:    1,
	}
	database.DB.Save(detail2)

	m := make([]string, 0)
	m = append(m, fmt.Sprintf("%s$%s/play/1/fromx", "->TO1", settings.UrlPath_TvOthers))
	m = append(m, fmt.Sprintf("%s$%s/play/b2/fromy", "->TO2", settings.UrlPath_TvOthers))
	m = append(m, fmt.Sprintf("%s$%s/play/b3/fromy", "->TO3", settings.UrlPath_TvOthers))

	var p2 *OthersPlayList
	p2 = &OthersPlayList{
		ID:           1,
		FolderId:     1,
		DetailId:     1,
		From:         "others",
		Vod_play_url: strings.Join(m, "#"),
	}
	database.DB.Save(p2)

	p2 = &OthersPlayList{
		ID:           2,
		FolderId:     1,
		DetailId:     2,
		From:         "others",
		Vod_play_url: strings.Join(m, "#"),
	}
	database.DB.Save(p2)

	p2 = &OthersPlayList{
		ID:           3,
		FolderId:     2,
		DetailId:     1,
		From:         "others",
		Vod_play_url: strings.Join(m, "#"),
	}
	database.DB.Save(p2)

	p2 = &OthersPlayList{
		ID:           4,
		FolderId:     2,
		DetailId:     2,
		From:         "others",
		Vod_play_url: strings.Join(m, "#"),
	}
	database.DB.Save(p2)

	p2 = &OthersPlayList{
		ID:           5,
		FolderId:     2,
		DetailId:     3,
		From:         "others",
		Vod_play_url: strings.Join(m, "#"),
	}
	database.DB.Save(p2)

}

//// 	// name$/-/-/id/from
// 	m = append(m, fmt.Sprintf("%s$%s/play/1/fromx", "->TO1", settings.UrlPath_TvOthers))
// 	m = append(m, fmt.Sprintf("%s$%s/play/b2/fromy", "->TO2", settings.UrlPath_TvOthers))
